<template>
  <div>
    <div>
      <label for="name">姓名</label>
      <input type="text" v-model="name" id="name" />
    </div>
    <div>
      <label for="phone">手机号</label>
      <input type="text" v-model="phone" id="phone" />
    </div>
    <div>
      <button @click="sub">提交订单</button>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      name: "",
      phone: "",
      uid: 0,
      goodid: 0
    };
  },
  mounted() {
    this.uid = localStorage.getItem("uid");
    this.goodid = this.$route.query.goodid;
    if (!this.uid) {
      this.$router.push("/login");
    }
  },
  methods: {
    sub: function() {
      let data = {
        name: this.name,
        phone: this.phone,
        uid: this.uid,
        goodid: this.goodid
      };

      this.axios({
        url: "http://127.0.0.1:8000/app01/order/",
        method: "post",
        data: data
      }).then(res => {
        alert(res.data.msg);
      });
    }
  }
};
</script>

<style scoped>
div {
  height: 30px;
}
</style>